<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;

/**
 * 空模块，主要用于显示404页面，请不要删除
 */
class FeedbackController extends HomeController{
	public  function getFeedback(){
		if(I('get.id')!=null){
			$id = I('get.id');
		}else{
			$id = 0;
		}

		if(I('get.page')!=null){
			$page = I('get.page');
		}else{
			$page = 1;
		}

		if(I('get.limit')!=null){
			$limit = I('get.limit');
		}else{
			$limit = 10;
		}

		if($id>0){
			$map['id'] = $id;
		}

		$map['status'] = 1;

		$feedbackModel = M('feedback');
		$feedback_data = $feedbackModel
		->page($page,$limit)
		->where($map)
		->select();
		foreach ($feedback_data as $key => $value) {
			$save_data[$key] = array(
			'name' => $feedback_data[$key]['name'], 
			'id' => $feedback_data[$key]['id'], 
			'create_time' => intval($feedback_data[$key]['create_time']), 
			'feedback' => $feedback_data[$key]['content'], 
			);
		}
		
		if($save_data){
			$json['success'] = true;
			$json['info'] = $save_data;
			$this->ajaxReturn($json,json,200);
		}else{
			$json['success'] = false;
			$this->ajaxReturn($json,json,400);
		}
		
	}

	public function addFeedback(){
		$data = json_decode(file_get_contents('php://input'),true);
		$uid =$this->login();
		$map['uid'] = $uid;
		if($uid){
			$name = M('ucenter_member')->where('id='.$uid)->field('username')->find();
			$map['name'] = $name['username'];
		}else{
			$json['error'] = '用户尚未登录';
		}

		if($data['feedback']!=null){
			$map['content'] = $data['feedback'];
		}else{
			$json['error'] = '反馈信息为空';
		}
		if(!$json['error']){
			$map['create_time'] = time();
			$map['status'] = 1;

			$feedbackModel = D('feedback');
			$feedback_data = $feedbackModel->addFeedback($map);
		}
		if($feedback_data){
			$json['success'] = true;
			$json['info'] = $feedback_data;
			$this->ajaxReturn($json,json,200);
		}else{
			$json['success'] = false;
			$this->ajaxReturn($json,json,400);
		}

	}
}
